#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include<fstream>
#include<sstream>
#include<cstring>
#include<string>
#include<vector>
#include <algorithm>
#include <iostream>
#include<climits>
#include<omp.h>
#include <arm_neon.h>
using namespace std;
ifstream ifs, ifs2;
int N=254;
int count0 = 0;
int count2 = 0;
std::vector<std::vector<int>> m(N, std::vector<int>(N, 0));
std::vector<std::vector<int>> n(N, std::vector<int>(N, 0));
typedef struct {
    int t_id; //线程 id
}threadParam_t;
const int NUM_THREADS=2;
void *threadFunc(void *param) {
threadParam_t *p = (threadParam_t*)param;
    int t_id = p -> t_id;
    if(t_id==0){
        ifs.open("x.txt", ios::in);
	    if (ifs.is_open())
	    {
	    	std::string buf;
	    	std::string buf2;
	    	while (std::getline(ifs, buf))
	    	{
	    		int count_;
	    		int number2;
	    		int tag2 = 0;
	    		if (std::getline(ifs, buf2)) {
	    			tag2 = 1;
	    		}
	    		std::istringstream zh(buf);
	    		int number;
	    		int tag = 0;
	    		if (tag2 == 1) {
	    			std::istringstream zh2(buf2);
	    			zh2 >> number2;
	    			count_ = N - 1 - number2;
	    			m[count_][N - 1 - number2] = 1;
	    			while (zh >> number) {
	    				if (tag == 0) {
	    					count0 = N - 1 - number;
	    					tag = 1;
	    				}
	    				m[count0][N - 1 - number] = 1;
	    				if (zh2 >> number2)
	    					m[count_][N - 1 - number2] = 1;
	    			}
	    			while (zh2 >> number2) {
	    				m[count_][N - 1 - number2] = 1;
	    			}
	    		}
	    		else {
	    			while (zh >> number) {
	    				if (tag == 0) {
	    					count0 = N - 1 - number;
	    					tag = 1;
	    				}
	    				m[count0][N - 1 - number] = 1;
	    			}
	    		}
	    	}

	    }
	    ifs.close();
    }
    if(t_id==1){
        ifs2.open("b.txt", ios::in);
	    if (ifs2.is_open())
	    {
	    	std::string buf2;
	    	std::string buf;
	    	while (std::getline(ifs2, buf))
	    	{
	    		int number2;
	    		int tag2 = 0;
	    		if (std::getline(ifs, buf2)) {
	    			tag2 = 1;
	    		}
	    		std::istringstream zh(buf);
	    		int number;
	    		if (tag2 == 1) {
	    			std::istringstream zh2(buf2);
	    			zh2 >> number2;
	    			n[count2+1][N - 1 - number2] = 1;
	    			while (zh >> number) {
	    				n[count2][N - 1 - number] = 1;
	    			}
	    			while (zh2 >> number2) {
	    				n[count2 + 1][N - 1 - number2] = 1;
	    			}
	    			count2 += 2;;
	    		}
	    		else {
	    			while (zh >> number) {
	    				n[count2][N - 1 - number] = 1;
	    			}
	    			count2++;
	    		}
	    	}

	    }//被消元行
	    ifs2.close();
    }
pthread_exit(NULL);
}

int main() {
	struct timespec sts, ets;
	timespec_get(&sts, TIME_UTC);
	pthread_t handles[NUM_THREADS];// 创建对应的 Handle
    threadParam_t param[NUM_THREADS];// 创建对应的线程数据结构
    for(int t_id = 0; t_id < NUM_THREADS; t_id++){
        param[t_id].t_id = t_id;
        pthread_create(&handles[t_id],NULL,threadFunc,(void*)&param[t_id]);
        }
    for(int t_id = 0; t_id < NUM_THREADS; t_id++){
        pthread_join(handles[t_id],NULL);
        }
	int index = 0;
	while (index <= count2) {
		for (int i = 0; i < N; i++) {
			if (n[index][i] == 1) {
				if (m[i][i] == 1) {
                    #pragma omp parallel num_threads(4)
                    {
                        int id=omp_get_thread_num();
                        for(int x=id*4;x<N;x+=16){
					        if(N-1 - x >= 4) {
					        	int32x4_t vec1 = vld1q_s32(&m[i][x]);// 
					        	int32x4_t vec2 = vld1q_s32(&n[index][x]); // 

					        	// 调用NEON函数进行异或操作
					        	int32x4_t result = veorq_s32(vec1, vec2);
					        	// 将结果存储回数组
					        	int* row_ptr = &n[index][x];
					        	vst1q_s32(row_ptr, result);
					        }
					        int j=N-N%4+1+id;
                            if(j<N){
		                        n[index][j] ^= m[i][j];
                            }
                            }
                    }
					if (i == N - 1) {
						index++;
					}
				}//减法
				else {
					int x = i;
					while (N - 1 - x >= 4) {
						int32x4_t result = vld1q_s32(&n[index][x]);
						int* row_ptr = &m[i][x];
						vst1q_s32((int32_t *)row_ptr, result);
						x += 4;
					}
					for (int j = x; j < N; j++) {
						m[i][j] = n[index][j];
					}//变成消元子
					index++;
					break;
				}
			}
			else {
				if (i == N - 1) {
					index++;
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (m[i][i] == 1) {
			for (int j = 0; j < N; j++) {
				if (m[i][j] == 1) {
					cout << N - 1 - j << " ";
				}
			}
			cout << endl;
		}
	}
	timespec_get(&ets, TIME_UTC);
	time_t dsec = ets.tv_sec - sts.tv_sec;
	long dnsec = ets.tv_nsec - sts.tv_nsec;
	if (dnsec < 0) {
		dsec--;
		dnsec += 1000000000;
	}
	std::printf("%ld.%09lds", dsec, dnsec);

	return 0;
}